package com.pe1n.yangtaopai.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.pe1n.yangtaopai.R;
import com.pe1n.yangtaopai.bean.CarBottomBean;
import com.pe1n.yangtaopai.page.detail.view.activity.DetailActivity;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by My on 2016/11/26.
 */

public class CarTopRecyclerAdapter extends RecyclerView.Adapter<CarTopRecyclerAdapter.MyViewHolder> {
    private Context mContext;//上下文
    private List<CarBottomBean.DataData.ProdListsData> mLsit;//数据源

    public CarTopRecyclerAdapter(Context mContext, List<CarBottomBean.DataData.ProdListsData> mLsit) {
        this.mContext = mContext;
        this.mLsit = mLsit;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.ft_car_item_rw_two_item,parent,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        final CarBottomBean.DataData.ProdListsData prodListsData=mLsit.get(position);
        String str=prodListsData.getImagePath();
        if(str!=null){
            Glide.with(mContext).load( str)
                    .placeholder(R.drawable.ytjx)
                    .into(holder.imageView);
        }

        holder.mTextView.setText("¥"+String.valueOf(prodListsData.getProdPrice()));
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mContext, DetailActivity.class);
                intent.putExtra("id",Integer.valueOf(prodListsData.getProdId()));
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return  mLsit.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        ImageView imageView;
        TextView mTextView;
        public MyViewHolder(View itemView) {
            super(itemView);
            imageView= (ImageView) itemView.findViewById(R.id.ft_car_item_rw_two_item_imageView);
            mTextView= (TextView) itemView.findViewById(R.id.ft_ca_textView);
        }
    }
}
